package com.zjy.springbootth.controller;

import com.zjy.springbootth.datasource.MyData;
import com.zjy.springbootth.entity.Book;
import com.zjy.springbootth.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * @program: springboot-th
 * @ClassName BookController
 * @description:
 * @author: Ats
 * @create: 2025-04-19 14:33
 * @Version 1.0
 */
@Controller
@RequestMapping("/book")
public class BookController {

    /**
     * 获取数据源
     */
    ArrayList<Book> books = MyData.getData();


    /**
     * 查询所有图书
     */
    @RequestMapping("/list")
    public String list(Model model, HttpSession session){
        // 1 模拟用户登录
        User user = new User("zhangsan", "ADMIN");
        // 2 将用户信息保存到session中
        session.setAttribute("user", user);
        // 3 将数据保存到model中
        model.addAttribute("books", books);
        // 4 跳转到books.html页面
        return "books";

    }
}
